<?php

/**
* SPECIAL OFFERS
* Copyright (c) 2012 
* Author: Dmitriy Tovkach (ragvalod@gmail.com)
* @license		GNU/GPL
**/

// No direct access
defined('_JEXEC') or die;

jimport('joomla.application.component.view');


class SpecialViewPromotion extends JView
{
	protected $state;
	protected $item;
	protected $form;

	/**
	 * Display the view
	 */
	public function display($tpl = null)
	{
		$this->state	= $this->get('State');
		$this->item		= $this->get('Item');
		$this->form		= $this->get('Form');

		// Check for errors.
		if (count($errors = $this->get('Errors'))) {
			JError::raiseError(500, implode("\n", $errors));
			return false;
		}

		$this->addToolbar();
		parent::display($tpl);
	}

	/**
	 * Add the page title and toolbar.
	 *
	 * @since	1.6
	 */
	protected function addToolbar()
	{
		JRequest::setVar('hidemainmenu', true);

		$user		= JFactory::getUser();
		$userId		= $user->get('id');
		$isNew		= ($this->item->id == 0);
		$checkedOut	= !($this->item->checked_out == 0 || $this->item->checked_out == $user->get('id'));


		JToolBarHelper::title(JText::_('COM_SPECIAL'), 'none.png');

			JToolBarHelper::apply('promotion.apply');
			JToolBarHelper::save('promotion.save');
			JToolBarHelper::save2new('promotion.save2new');
	
		if (empty($this->item->id)) {
			JToolBarHelper::cancel('promotion.cancel');
		}
		else {
			JToolBarHelper::cancel('promotion.cancel', 'JTOOLBAR_CLOSE');
		}

		JToolBarHelper::divider();
		
	}
}
